package com.zpeb.pdd.controller;


import com.zpeb.pdd.entity.User;
import com.zpeb.pdd.service.UserInfo;
import com.zpeb.pdd.utils.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName pdd
 * @Description: TODO
 * @date ${DAT}10:29
 */
@RestController
@RequestMapping("user")
public class UserConrtoller {

    @Autowired
    UserInfo userInfo;

    /**
     * 根据ID来查询用户列表
     * @param id
     * @return
     * @throws Exception
     */
    @GetMapping("{id}")
    public Msg selectById(@PathVariable String id) throws Exception {
        return Msg.success().add("msg",userInfo.selectById(id));
    }

    /**
     * 显示所有用户列表
     * @return
     * @throws Exception
     */
    @GetMapping
    public Msg selectAll()throws Exception{
        return Msg.success().add("msg",userInfo.selectAll());
    }

    /**
     * 添加
     * @param user
     * @return
     * @throws Exception
     */
    @PostMapping
    public Msg addUser(@RequestBody  User user) throws Exception{
        return Msg.success().add("msg","成功添加"+userInfo.addUser(user)+"条信息");
    }

    /**
     * 修改用户信息
     * @param user
     * @param id
     * @return
     * @throws Exception
     */
    @PutMapping("{id}")
    public Msg updateUser(@RequestBody User user,
                          @PathVariable String id) throws Exception{
            int result = userInfo.updateUser(user,id);
            return Msg.success().add("msg","成功更新"+result+"结果");
    }

    /**
     * 删除用户
     * @param id
     * @return
     * @throws Exception
     */
    @DeleteMapping("{id}")
    public Msg deleteUser(@PathVariable String id) throws Exception{
        return Msg.success().add("msg","成功删除"+userInfo.deleteUser(id)+"条数据");
    }

    /**
     * 获得商户列表
     * @return
     * @throws Exception
     */
    @GetMapping("roleB")
    public Msg RoleBUser()throws Exception{
        return Msg.success().add("msg",userInfo.getRoleBUser());
    }

    /**
     * 获得客户列表
     * @return
     * @throws Exception
     */
    @GetMapping("roleC")
    public Msg RoleAUser()throws Exception{
        return Msg.success().add("msg",userInfo.getRoleCUser());
    }

}
